import axios from 'axios'
import { nanoid } from 'nanoid'
export default {
    namespaced:true,
    actions:{
        addPersonWang(context,value){
            if(value.name.indexOf('王')===0){
                context.commit('ADDPerson',value)
            }
        },
        addPersonServer(context){
            axios.get('https://api.uixsj.cn/hitokoto/get?type=socia1').then(response=>{
                context.commit('ADDPerson',{id:nanoid(),name:response.data})
            },error=>{
                alert(error.message)
            })
        }
    },
    mutations:{
        ADDPerson(state,value){
            state.personList.unshift(value)
        }
    },
    state:{
        personList:[
            {id:'001',name:'aaa'},
            {id:'002',name:'bbb'}
        ]
    },
    getters:{
        firstPersonName(state){
            return state.personList[0].name
        }
    }
}